package Componentes;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.*;
import javax.swing.*;

public final class GlassPanel extends JComponent {

    private Image image = null;
    private Icon icon;

    public GlassPanel() {
        this.setVisible(false);
        addMouseListener(new MouseAdapter() {
        });
        addMouseMotionListener(new MouseMotionAdapter() {
        });
        addKeyListener(new KeyAdapter() {
        });

        setFocusTraversalKeysEnabled(false);
        addComponentListener(new ComponentAdapter() {

            @Override
            public void componentShown(ComponentEvent evt) {
                requestFocusInWindow();
            }
        });

        //this.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recursos/Imagenes/img.gif")));
        // setBackground(new Color(220,230,240));
        setBackground(new Color(121, 137, 167));
        Timer timer = new Timer(100, new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                repaint();
            }
        });
        timer.start();
        //[220,230,240]
        //setBackground(Color.CYAN);
        //setBackground(Color.BLACK);
        // setBackground(Color.WHITE);
    }

    @Override
    protected void paintComponent(Graphics g) {
        Dimension frameSize = this.getParent().getSize();
        Graphics2D g2 = (Graphics2D) g;


        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);

        Rectangle clip = g.getClipBounds();

        AlphaComposite alpha = AlphaComposite.SrcOver.derive(0.75f);
        Composite composite = g2.getComposite();
        g2.setComposite(alpha);

        g2.setColor(getBackground());
        g2.fillRect(clip.x, clip.y, clip.width, clip.height);
        if (image != null) {
            g2.drawImage(image, (frameSize.width - image.getWidth(this)) / 2, (frameSize.height - image.getHeight(this)) / 2, 480, 270, null);
        }
        g2.setComposite(composite);

    }

    public Icon getIcon() {
        return icon;
    }

    public void setIcon(Icon icon) {
        this.icon = icon;
        if (icon != null) {
            image = ((ImageIcon) icon).getImage();
        }
    }
}
